Add some helpful utilities#42
Conversation
|
Oh, sorry @NullVoxPopuli I think we misunderstood each other in the discussion in #41. I'm happy to continue discussing this, but I was saying that especially with RFC 726 pending, I don't really want to build utilities into So I was saying, I'd definitely be into exporting a |
|
qunit-dom and test-helpers don't do anything with actually authoring page-objects though. Like, you need utilities like this regardless of RFC 726 landing |
|
I see. Okay, I'm sold on |
couple:
In my case, for some libraries, I'm considering all DOM is private API, and only using
but |
|
Got it. I'm resistant to
It's harder for me to think about But I also do want to expose the primitives that would enable users to implement things like
|
|
changes made! |
| * A utility interface that can be unioned with a {@link PageObject} | ||
| * to denote that the `element` is _known_ to exist | ||
| */ | ||
| export interface WithElement { |
There was a problem hiding this comment.
We already have a WithElement interface that's more targeted to PageObject and therefore IMO easier to use for its intended purpose. So let's update this one to look like that one, and then make array-proxy.ts import/use this instead of having its own.
| /** | ||
| * Utility to get the fully resolved selector path of a {@link PageObject} | ||
| */ | ||
| export function getDescription(pageObject: PageObject): string { |
There was a problem hiding this comment.
Can I just express my sincere and emphatic support of getDescription I've run into this many times and every time I come back disappointed that there is not a clean way to get the current selector string. The two main cases I've discovered so far are…
In debugging. Element not found is not very easy to discover where it is while selector '… … …' not found can really help someone staring at the Browser's console inspector to find where the typo is.
When using 3rd party test helpers. For example, ember-power-calendar has a calendarSelect() helper where the first param must be a string because it concatenates its own nested selectors on the one you passed. But as is now we can't convert a fractal-p-o selector back into the full selector from it's .element property.
Having this one escape hatch would make composing Page Objects not only easier to debug but also encourage the use of PageObjects like Martin Fowler originally envisioned by allowing developers to design a fractal-p-o with better methods especially methods that hook into 3rd party test helpers.
class Foo extends PageObject {
form = selector('[data-test-selector=my-form]', class extends PageObject {
calendar = selector('ember-power-calendar', class extends PageObject {
selectDate(date) {
return calendarSelect(getDescription(this), date);
}
});
});
}There was a problem hiding this comment.
Thanks for the feedback @sukima! Relatedly, if you haven't read emberjs/rfcs#726 yet, I'd love to hear any thoughts/feedback you have on it. I'm hoping to make a push to get it moving again soon...
Get that coverage back up to 100%!
|
Released in v0.2.2 -- thanks @NullVoxPopuli! |
|
yay! thanks! |
#41